﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AnalisisDeRiesgos.Models;

namespace AnalisisDeRiesgos.Controllers
{
    public class ConfigurationController : Controller
    {
        //
        // GET: /Configuration/

        public ActionResult Index()
        {
            if (!Utils.HasPrivilege(Convert.ToInt32(Session["userid"]), Privileges.Administrator))
                return RedirectToAction("LogOn", "User");

            ConfigurationModel model = new ConfigurationModel();
            return View(model);
        }

        [HttpPost]
        public ActionResult Index(ConfigurationModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return View();
                }

                model.Save();
                return RedirectToAction("Index", "Home");
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
                return View(model);
            }
        }

    }
}
